package cn.schoolwow.util.module.query.resource.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.apache.commons.io.IOUtils;

import java.net.URL;
import java.nio.charset.StandardCharsets;

public class GetAsStringFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        URL url = (URL) flowContext.checkData("url");

        String content = IOUtils.toString(url, StandardCharsets.UTF_8);
        flowContext.putReturnData("content", content);
    }

    @Override
    public String name() {
        return "读取资源并返回字符串";
    }
}
